import { createSlice } from '@reduxjs/toolkit'

const authSlice = createSlice({
  name: 'auth',
  initialState: {
    token: sessionStorage.getItem('token') || null,
    menuList: [],
  },
  reducers: {
    setToken: (state, action) => {
      state.token = action.payload
      localStorage.setItem('token', action.payload)
    },
    clearToken: (state) => {
      state.token = null
      localStorage.removeItem('token')
    },
    setRouterMenuList: (state, action) => {
      state.menuList = action.payload
    },
  },
})
export const { setToken, clearToken, setRouterMenuList } = authSlice.actions
export default authSlice.reducer
